package com.spider.service;

import com.spider.entites.User;
import com.spider.mapper.UserMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author panglin
 * @date 2020/11/19 10:41
 */
@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    public User getUser(User user) {
        return this.userMapper.getUser(user);
    }

    public List<User> getUsers(String info, Integer num, Integer size) {
        if (!StringUtils.isEmpty(info)) {
            info = "%" + info + "%";
        } else {
            info = null;
        }
        return this.userMapper.getUsers(info, (num - 1) * size, size);
    }

    public Integer addUser(User user) {
        user.setCreateTime(new Date());
        user.setSalt("spider");
        return this.userMapper.addUser(user);
    }

    public Integer getTotal(String info) {
        if (!StringUtils.isEmpty(info)) {
            info = "%" + info + "%";
        } else {
            info = null;
        }
        return this.userMapper.getTotal(info);
    }

    public Integer deleteByName(String name) {
        return this.userMapper.deleteByName(name);
    }

    public User getUserById(Integer id) {
        return this.userMapper.getUserById(id);
    }

    public Integer updateUserById(User user) {
        return this.userMapper.updateUserById(user);
    }
}
